package com.greensam.common.exception;

import com.greensam.common.mq.ResultCode;
import lombok.Getter;

import java.io.Serial;

/**
 * 自定义异常类
 * @Author:  Machengrui
 * @Date: 2024/9/23 16:26
 */
public class GreensamApiException extends RuntimeException {

    /**
     * 用于序列化和反序列化Java对象的版本号
     */
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 私有变量，用于存储异常对应的错误码。不同的错误码可以代表不同的错误类型
     */
    @Getter
    private long code;

    /**
     * 不可变的私有字符串变量message，用于存储异常的描述信息。final关键字表明一旦赋值就不能再被修改
     */
    private final String message;

    /**
     * 私有变量，用于存储格式化消息可能需要用到的参数。这些参数可以用来替换消息字符串中的占位符
     */
    @Getter
    private Object[] params;

    public GreensamApiException(String message) {
        super(message);
        this.message = message;
        this.code = ResultCode.FAILED.getCode();
    }

    public GreensamApiException(String message, Object[] params) {
        super(message);
        this.message = message;
        this.params = params;
        this.code = ResultCode.FAILED.getCode();
    }

    public GreensamApiException(String message, long code) {
        super(message);
        this.message = message;
        this.code = code;
    }

    public GreensamApiException(String message, long code, Object[] params) {
        super(message);
        this.message = message;
        this.code = code;
        this.params = params;
    }

    public GreensamApiException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
    }

    @Override
    public String getMessage() {
        return super.getMessage();
    }

}